package com.cxb.receiver;

import com.cxb.MainActivity;
import com.cxb.utils.CommonUtils;
import com.cxb.utils.Tts;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.PowerManager;

public class TTSReceiver extends BroadcastReceiver {

	private PowerManager mPowerManager;

	@Override
	public void onReceive(Context context, Intent intent) {

		mPowerManager = (PowerManager) context
				.getSystemService(Context.POWER_SERVICE);
		final String data = intent.getStringExtra("data");
		if (mPowerManager.isScreenOn()) {
			if (data != null && MainActivity.tts != null) {
				Tts.speak(data);
			}
		}else{
			CommonUtils.wakeUpScreen(context);
			new Handler().postDelayed(new Runnable() {
				
				@Override
				public void run() {
					if (data != null && MainActivity.tts != null) {
						Tts.speak(data);
					}
					
				}
			}, 2000);
		}
	}

}
